package cn.itsy.dao.duct;

import cn.itsy.pojo.Duct;
import cn.itsy.pojo.Emp;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-05-30 8:24
 */
@Repository(value = "ductDaoimpl")
public class DuctDaoimpl implements DuctDao {
    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Duct> queryAllDucType(String sql) {
        List<Duct> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Duct>(Duct.class));
        return query;
    }

    @Override
    public Integer updateDuctNameById(String sql, Duct duct) {
        int update = this.jdbcTemplate.update(sql, duct.getId(), duct.getZbian(), duct.getZname(), duct.getDuctypeId(), duct.getZdj(), duct.getId());
        return update;
    }

    @Override
    public Integer updateDuctNameById(String sql, Duct duct, Integer oldId) {
        int update = this.jdbcTemplate.update(sql, duct.getId(), duct.getZbian(), duct.getZname(), duct.getDuctypeId(), duct.getZdj(), oldId);
        return update;
    }

    /**
     * 删除职务表的方法
     *
     * @param sql
     * @param duct
     * @return
     */
    @Override
    public Integer deleteDuctById(String sql, Duct duct) {
        int update = this.jdbcTemplate.update(sql, duct.getId());
        return update;
    }

    @Override
    public List<Emp> queryEmpById(String sql, Duct duct) {
        List<Emp> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Emp>(Emp.class), duct.getId());
        return query;
    }
}
